var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/util/index.ts
var util_exports = {};
__export(util_exports, {
  getFileCenterApiUrl: () => getFileCenterApiUrl,
  getGlobalContainer: () => getGlobalContainer,
  getIUPFilePreviewUrl: () => getIUPFilePreviewUrl,
  getRegisterComponent: () => getRegisterComponent,
  getRegisterComponentWithProps: () => getRegisterComponentWithProps,
  iup: () => iup,
  registerComponent: () => registerComponent,
  useRefreshList: () => useRefreshList
});
module.exports = __toCommonJS(util_exports);
var import_iup_core = require("@newgrand/iup-core");
var import_react = require("react");
var import_common = require("./common");
__reExport(util_exports, require("@newgrand/iup-core"), module.exports);
var iup = {
  ...import_iup_core.core,
  ...import_common.CommonUtil,
  registerExternal(obj) {
    import_iup_core.core.registerExternal(obj, false);
  }
};
function registerComponent(Components, options) {
  (0, import_iup_core.registerCpts)(Components, { ...options, platform: "pc" });
}
function getRegisterComponent(type = "", candidate = "") {
  return (0, import_iup_core.getRegisterCpt)(type, "pc", candidate);
}
function getRegisterComponentWithProps(type = "", candidate = "") {
  return (0, import_iup_core.getRegisterCptWithProps)(type, "pc", candidate);
}
function useRefreshList(effect, busType) {
  (0, import_react.useEffect)(() => {
    return import_common.CommonUtil.onRefreshList(busType, effect);
  }, []);
}
function getGlobalContainer() {
  var _a, _b;
  const name = (_b = (_a = iup.external).getQianKun) == null ? void 0 : _b.call(_a).name;
  return name ? document.body.querySelector(`div[data-qiankun="${name}"]`) || document.body : document.body;
}
function getFileCenterApiUrl(relativeUrl) {
  const { fileUrl } = iup.getUser();
  return {
    absUrl: fileUrl ? true : false,
    url: fileUrl ? `${fileUrl}${relativeUrl}` : relativeUrl
  };
}
var isDev = process.env.NODE_ENV === "development";
function getIUPFilePreviewUrl(fileId) {
  const { accessToken } = iup.getUser();
  const { url, absUrl } = getFileCenterApiUrl(`/iup-file/doc/file/preview?fileId=${fileId}&User-Token=${accessToken}`);
  const nextUrl = absUrl ? url : `${isDev ? "/proxy" : location.origin}${url}`;
  return {
    url: nextUrl,
    absUrl
  };
}
(0, import_iup_core.setGlobalVar)("$iup", iup);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getFileCenterApiUrl,
  getGlobalContainer,
  getIUPFilePreviewUrl,
  getRegisterComponent,
  getRegisterComponentWithProps,
  iup,
  registerComponent,
  useRefreshList,
  ...require("@newgrand/iup-core")
});
